﻿package app.view.components.guiDima 
{
	import app.model.RemoteProxy;
	import app.view.components.guiDima.slideShowD.Image;
	import app.view.events.UIEvent;
	import com.snzflash.components.list.ListItemRenderer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 * По сути кнопка "событие"
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@yandex.ru
	 */
	public class EventItemDBase extends ListItemRenderer
	{
		// app.view.components.guiDima.EventItemDBase
		
		//	public
		public static const WIDTH:Number = 230;
		public static const HEIGHT:Number = 290;
		
		public static const IMAGE_WIDTH:Number = 200;
		public static const IMAGE_HEIGHT:Number = 140;
		public static const GAP_V:Number = 25;
		public static const GAP_H:Number = 25;
		private var _image:Image;
		public var time:TextField;
		public var nameEvent:TextField;
		public var bgdImage:Sprite;
		
		//	private
		
		//	const
		
		//	CONSTRUCTOR
		public function EventItemDBase() 
		{
			super();
			
		}
		
		//	METHODS
		//	private
		override protected function init():void
		{
			super.init();
			
			nameEvent.multiline = true;
			nameEvent.wordWrap = true;
			
			time.text = '';
			nameEvent.htmlText = '';
			
			graphics.beginFill(0xff0000,0);
			graphics.drawRect(0, 0, WIDTH, HEIGHT);
			graphics.endFill();
			
			//trace('bgd',bgdImage.width,bgdImage.height);
			
			_image = new Image(bgdImage.width, bgdImage.height, Image.RESIZE_MAX, Image.ALIGN_CENTER);
			addChild(_image);
			_image.x = bgdImage.x;
			_image.y = bgdImage.y;
			
			addChild(bgdImage);
		};
		
		private function setEvents():void
		{
			doubleClickEnabled = true;
			//addEventListener(MouseEvent.ROLL_OVER, onItemOver);
			//addEventListener(MouseEvent.ROLL_OUT, onItemOut);
			addEventListener(MouseEvent.MOUSE_DOWN, onClick);
		}
		
		private function removeEvents():void
		{
			//removeEventListener(MouseEvent.ROLL_OVER, onItemOver);
			//removeEventListener(MouseEvent.ROLL_OUT, onItemOut);
			removeEventListener(MouseEvent.MOUSE_DOWN, onClick);
		}
		
		override public function destroy():void 
		{
			super.destroy();
			
			removeEvents();
			
			_image.destroy();
			removeChild(_image);
			
			
		};
		
		override public function get data():Object { return super.data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			trace('item data', data.id);
			
			/*for (var name:String in _data.event) 
			{
				trace('name = ', name);
			}
			trace('------------------');*/
			
			// парс для события
			//trace('1',_data.event.text[1]);
			//trace('2',_data.event.text[2]);
			//trace('3',_data.event.text[3]);
			//trace('1',_data.data.event[1].text[2]);
			//trace('1',_data.data.event[1].text[3]);
			//trace('1',RemoteProxy.DOMEN+_data.data.event[1].image[1].image_path);
			
			//trace('url',  _data.event.image[1].image_path);
			
			if (_data.event.image[1].image_path!='' && _data.event.image[1].image_path) 
			{
				_image.loadImage(RemoteProxy.DOMEN + _data.event.image[1].image_path);
			}else
			{
				
			}
			
			time.text = _data.event.text[1];
			nameEvent.htmlText = _data.event.text[2];
			
			setEvents();
			
			selected = false;
		};
		
		override public function get selected():Boolean { return _selected; };
		
		override public function set selected(value:Boolean):void 
		{
			_selected = value;
			
			/*if (_selected==true) 
			{
				removeEvents();
				buttonMode = useHandCursor = false;
			}else
			{
				setEvents();
				buttonMode = useHandCursor = true;
			}*/
			
			setEvents();
			buttonMode = useHandCursor = true;
		};
		
		private function onClick(e:MouseEvent):void 
		{
			//trace('click popup');
			
			var ev:UIEvent = new UIEvent(UIEvent.CLICK_ITEM_EVENT);
			ev.data = data;
			dispatchEvent(ev);
			
		}
	}

}